/*
 * @Author: 飞越疯人院 353362604@qq.com
 * @Date: 2022-09-13 13:42:20
 * @LastEditors: 飞越疯人院 353362604@qq.com
 * @LastEditTime: 2022-12-28 16:01:33
 * @FilePath: \adminstration\src\Common\Router\MenuNavList\Environmental\EnvironmentData.jsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import {
    AddDataButton,
    ModDataButton,
    DelDataButton,
    ExecuteButton,
    OpenTwoRouter,
    SelectExcelButton,
} from '../Common/options'
import { IdentityLevel } from '../Common/Conversion'

import { project } from '../../../Data'
const { client_id } = project[window.location.hostname]

const independenceList = {
    'jtgjadmin.ljkjkf.com': 'organizationUuid',
    'jtgjadmin.hljsjtgj.com': 'organizationUuid',
}

export const User = async ({ url, OptionsEvent, ClientData, actionRef, Permission }) => {
    const { hostname } = window.location
    let data = {
        type: '系统设置',
        pageSize: 10,
        params: { pageIndex: 1 },
        // hideInSearch: true,
        independenceSet: {
            title: '组织机构',
            url: 'getOrgTree',
            data: { IsByUserUuid: 1 },
            type: 'TableNavTree001',
            all: true,
        },
        independence: independenceList[hostname],
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            <SelectExcelButton
                key="excel"
                title="导出Excel"
                OptionsEvent={OptionsEvent}
                api={API_LIST()['getUserExcel']}
            />,
            Permission?.findIndex(v => v.uuid === '3276ea87-67d8-4232-a0ef-b9b79fd72750') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} url={url} type="primary" icon="add" title="新增用户" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.tableName, title: '账户' },
            // {
            //     dataIndex: 'password',
            //     title: '密码',
            //     valueType: 'input',
            //     width: 150,
            //     hideInAdded: true,
            //     hideInModify: true,
            //     hideInSearch: true,
            // },
            { ...commonTableList.fullName, title: '姓名' },
            {
                dataIndex: 'mobile',
                title: '手机号码',
                valueType: 'input',
                rules: client_id !== 'wisdom9a',
                width: 150,
            },
            {
                dataIndex: 'idCard',
                title: '身份证号',
                valueType: 'input',
                rules: client_id !== 'wisdom9a',
                width: 180,
                hideInSearch: true,
            },

            // 二改
            {
                dataIndex: 'userProjects',
                title: '项目',
                valueType: 'select',
                valueEnum: ClientData.project,
                multiple: true,
                hideInSearch: true,
                rules: true,
                width: 200,
                hideInTable: true,
            },
            {
                ...commonTableList.organizationUuid,
                dataIndex: 'userOrganizations',
                valueEnum: ClientData.organization,
                multiple: true,
                hideInSearch: true,
                width: 200,
            },

            {
                dataIndex: 'userRoles',
                title: '角色',
                valueType: 'select',
                valueEnum: ClientData.role,
                multiple: true,
                hideInSearch: true,
                rules: true,
                width: 200,
            },

            client_id !== 'wisdom9a' && {
                dataIndex: 'noDisturbing',
                title: '免打扰',
                valueType: 'select',
                valueEnum: BuiltInData.isEnabled,
                rules: true,
                width: 100,
                hideInSearch: true,
            },
            client_id !== 'wisdom9a' && {
                dataIndex: 'isLocked',
                title: '锁定',
                valueType: 'select',
                valueEnum: BuiltInData.locking,
                rules: true,
                hideInSearch: true,
                width: 100,
            },
            client_id !== 'wisdom9a' && {
                dataIndex: 'validPeriod',
                title: '有效期',
                valueType: 'Date',
                rules: true,
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'identityUuid',
                title: '用户身份',
                valueType: 'select',
                valueEnum: await IdentityLevel(),
                hideInSearch: true,
                width: 100,
            },

            { ...commonTableList.isEnabled, rules: true },

            client_id !== 'wisdom9a' && { ...commonTableList.sortId, rules: true },
            client_id !== 'wisdom9a' && commonTableList.remark,
            client_id !== 'wisdom9a' && commonTableList.createUserName,
            client_id !== 'wisdom9a' && commonTableList.createTime,
            client_id !== 'wisdom9a' && commonTableList.updateUserName,
            client_id !== 'wisdom9a' && commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 400,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid } = record
                    return [
                        Permission.findIndex(v => v.uuid === '1164393f-19c3-4348-98fd-e33d0b2cdcd2') !== -1 && (
                            <ModDataButton
                                OptionsEvent={OptionsEvent}
                                key="modify"
                                title="修改"
                                url={url}
                                data={record}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === '89909522-0055-459d-859e-200591853694') !== -1 && (
                            <ExecuteButton
                                actionRef={actionRef}
                                key="Reset"
                                title="重置密码"
                                url="posUserResetPassword"
                                path={[uuid]}
                                tips="密码重置成功!"
                            />
                        ),
                        Permission.findIndex(v => v.uuid === '7a3ab8d6-7c09-412b-ba02-789173d8fa72') !== -1 && (
                            <ExecuteButton
                                actionRef={actionRef}
                                key="UpLoadUserBtn"
                                title="上传信息"
                                url="posUserUpLoadUser"
                                path={[uuid]}
                                tips="信息上传成功!"
                            />
                        ),

                        <OpenTwoRouter
                            key="TwoOne"
                            title="从属关系"
                            twoTitle="用户间从属关系"
                            modal="TableList"
                            OptionsEvent={OptionsEvent}
                            other={{
                                page: 'User',
                                Permission,
                                oneData: record,
                                header: data.columns,
                                ClientData,
                            }}
                        />,
                        Permission.findIndex(v => v.uuid === '77908f1b-0701-438c-b8ec-873f5845bc72') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="delete"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
